//
//  BankCardCell.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/6.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "BankCardCell.h"

@interface BankCardCell ()

@property (nonatomic, strong) UIImageView *bankImageView;
@property (nonatomic, strong) UIImageView *logoImageView;
@property (nonatomic, strong) UIImageView *selectImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *numberLabel;

@end

@implementation BankCardCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = ListMaoBackgroundColor;
        
        [self.bankImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(15);
            make.top.mas_equalTo(self.contentView.mas_top).offset(15);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
            make.bottom.mas_equalTo(self.contentView);
        }];
        [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(40, 40));
            make.left.mas_equalTo(self.bankImageView.mas_left).offset(15);
            make.top.mas_equalTo(self.bankImageView.mas_top).offset(15);
        }];
        [self.selectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(33, 33));
            make.top.mas_equalTo(self.bankImageView.mas_top).offset(0);
            make.right.mas_equalTo(self.bankImageView.mas_right).offset(0);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.logoImageView.mas_right).offset(10);
            make.centerY.mas_equalTo(self.logoImageView);
        }];
        [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.bankImageView.mas_left).offset(20);
            make.bottom.mas_equalTo(self.bankImageView.mas_bottom).offset(-30);
        }];
        
    }
    return self;
}

- (void)updateInfoCellWithModel:(BankInfoModel *)model {
//    self.bankImageView.image = [UIImage imageNamed:@"card_gongshang"];
    [self.bankImageView sd_setImageWithURL:[NSURL URLWithString:model.background] placeholderImage:[UIImage imageNamed:@"card_replace"]];
    [self.logoImageView sd_setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:[UIImage imageNamed:@"logo_replace"]];
    self.titleLabel.text = model.bankName;
    self.numberLabel.text = model.bankCardnumber;
    if ([model.isDefault isEqualToString:@"1"]) {
        self.selectImageView.hidden = NO;
    }else{
        self.selectImageView.hidden = YES;
    }
}

- (UIImageView *)bankImageView {
    
    if (!_bankImageView) {
        _bankImageView = [[UIImageView alloc] init];
//        [_bankImageView setContentMode:UIViewContentModeScaleAspectFit];
        _bankImageView.layer.cornerRadius = 4;
        _bankImageView.layer.masksToBounds = YES;
        
        [self.contentView addSubview:_bankImageView];
    }
    return _bankImageView;
}
- (UIImageView *)logoImageView {
    
    if (!_logoImageView) {
        _logoImageView = [[UIImageView alloc] init];
//        [_logoImageView setContentMode:UIViewContentModeScaleAspectFit];
        _logoImageView.layer.cornerRadius = 20;
        _logoImageView.layer.masksToBounds = YES;
        
        [self.contentView addSubview:_logoImageView];
    }
    return _logoImageView;
}
- (UIImageView *)selectImageView {
    
    if (!_selectImageView) {
        _selectImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bankduihao"]];
        [_selectImageView setContentMode:UIViewContentModeScaleAspectFit];
        
        [self.contentView addSubview:_selectImageView];
    }
    return _selectImageView;
}

- (UILabel *)titleLabel {
    
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15];
        [_titleLabel setTextAlignment:NSTextAlignmentLeft];
        
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UILabel *)numberLabel {
    
    if (!_numberLabel) {
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.textColor = [UIColor whiteColor];
        _numberLabel.font = [UIFont boldSystemFontOfSize:20];
        [_numberLabel setTextAlignment:NSTextAlignmentCenter];
        
        [self.contentView addSubview:_numberLabel];
    }
    return _numberLabel;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
